package com.bodu.system.service.impl;

import com.bodu.core.entity.ParamReq;
import com.bodu.system.entity.request.LoginLogRequest;
import com.bodu.system.entity.vo.LoginLogVo;
import com.bodu.system.mapper.LoginLogMapper;
import com.bodu.system.service.LoginLogService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 登录日志 Service impl
 *
 * @author Administrator
 */
@Service
public class LoginLogServiceImpl implements LoginLogService {

    @Resource
    private LoginLogMapper loginLogMapper;

    @Override
    public LoginLogVo getModel(Long id) {
        return loginLogMapper.getModel(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Long save(LoginLogRequest request) {
        loginLogMapper.save(request);
        return request.getId();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Long update(LoginLogRequest request) {
        loginLogMapper.update(request);
        return request.getId();
    }

    @Override
    public List<LoginLogVo> listPage(ParamReq<LoginLogRequest> params) {
        List<LoginLogVo> res = loginLogMapper.listPage(params);
        res.forEach(r -> {
            r.setStatusFlagName(r.getStatusFlag() == 0 ? "成功" : "失败");
        });
        return res;
    }

    @Override
    public Integer countPage(ParamReq<LoginLogRequest> params) {
        return loginLogMapper.countPage(params);
    }

    @Override
    public Integer updateDelFlagById(Long id, Integer delFlag) {
        return loginLogMapper.updateDelFlagById(id, delFlag);
    }

}
